package com.yusong.open.sdk.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by yusong on 2018/1/8/008.
 * 掩码工具类
 */
public class MarkUtil {
    private static final Logger logger = LoggerFactory.getLogger(MarkUtil.class);

    /*
    *手机号掩码
    */
    public static String mobile(String mobile){
        if (ListStrUtil.isEmpty(mobile) || mobile.length() != 11){
            return mobile;
        }
        String res = mobile.substring(0,3)+"****"+mobile.substring(7,11);
        return res;
    }

    /*
    *昵称掩码
    */
    private static String mark(String nickname){
        if(ListStrUtil.isEmpty(nickname)){
            return nickname;
        }
        int length = nickname.length();
        String result ;
        if(length == 1){
            result = nickname;
        }else if(length <= 2){
            result = "*"+ nickname.substring(1,length );
        }else {
            result = nickname.substring(0,2)+"***"+ nickname.substring(length -2,length );
        }
        return result;
    }

    public static String markSave(String nickname){
        String res = null;
        try {
            res = mark(nickname);
        } catch (Exception e) {
            logger.error("nicknameSave|{}",nickname,e);
            return nickname;
        }
        return res;
    }




} 